require 'login_system'
require 'rexml/document'
require 'open-uri'
class Plugin::LastfmController < ActionController::Base
  before_filter :set_site_template_root
  def set_site_template_root
    self.class.template_root = "#{RAILS_ROOT}/components/"
    @template.base_path = template_root
  end 
  include LoginSystem
  before_filter :login_required, :only => [:config]
  def show
    @plugin=Extplugin.find_by_name("lastfm")
	@config=@plugin.config 
    if @plugin.activated==1
      url="http://ws.audioscrobbler.com/1.0/user/"+@config["lastfmuser"]+"/recenttracks.xml"
	  @doc=REXML::Document.new(open(url).read)
	  @list=REXML::XPath.match(@doc,'//track')
	  profile_url="http://ws.audioscrobbler.com/1.0/user/"+@config["lastfmuser"]+"/profile.xml"
	  @profile=REXML::Document.new(open(profile_url).read)
  	  render(:layout => false)
  	else
  	  render :text => _("not activated")
  	end 
  end
	
  def config
    @plugin=Extplugin.find_by_name("lastfm")
    @config=@plugin.config 
  end
  
end